Skip to content

✨ WithLowPriorityWhenUnchanged: Set Priority for all add methods #3290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

alvaroaleman
Copy link
Member

This change makes WithLowPriorityWhenUnchanged set the priority for
AddAfter, AddRatelimited and AddWithOpts (if not already set) as well.

Fixes #3171

Based on top of #3289 so that needs to merge first
/hold

Making the priority opt a pointer allows to dinstinguish "unset" from
"0". While this is irrelevant for the priorityqueue itself, it is
required for any wrapper that wants to inject a default priority
without overriding one that was explicitly set.
This change makes `WithLowPriorityWhenUnchanged` set the priority for
AddAfter, AddRatelimited and AddWithOpts (if not already set) as well.
@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Aug 19, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alvaroaleman

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 19, 2025
@k8s-ci-robot k8s-ci-robot requested a review from FillZpp August 19, 2025 01:34
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 19, 2025
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 19, 2025
addFunc func(item request, q workqueue.TypedRateLimitingInterface[request])
type workqueueWithDefaultPriority[request comparable] struct {
priorityqueue.PriorityQueue[request]
priority int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should also make this a pointer

So that we only call AddWithOpts with a priority if it is actually set (and not &0 if unset)

I know that currently for our priority queue implementation it doesn't matter (as far as I can tell), still wondering if it would be better

@@ -223,7 +226,7 @@ func addToQueueCreate[T client.Object, request comparable](q workqueue.TypedRate
if evt.IsInInitialList {
priority = LowPriority
}
priorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: priority}, item)
priorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: &priority}, item)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar here. Wondering if we should just play it safe

	var priority *int
	if evt.IsInInitialList {
		priority = ptr.To(LowPriority)
	}
	priorityQueue.AddWithOpts(priorityqueue.AddOpts{Priority: priority}, item)

(same in l.245)

} else {
Expect(actualOpts).To(Or(
Equal(priorityqueue.AddOpts{After: test.after, RateLimited: test.ratelimited}),
Equal(priorityqueue.AddOpts{After: test.after, RateLimited: test.ratelimited, Priority: ptr.To(0)}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if this line should be here (if we make the changes I suggested in eventhandler.go)

(same in l.1081)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

WithLowPriorityWhenUnchanged only sets priority for Add
3 participants